﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Models;
using DAL;
namespace BLL
{
    public class PictureFileManager
    {
        PictureFileService objPictureFileService = new PictureFileService();
        /// <summary>
        /// 根据项目工程的ID号获取图片
        /// </summary>
        /// <param name="id">工程ID</param>
        /// <returns></returns>
        public PictureFile GetPictureById(string id)
        {
            return objPictureFileService.GetPictureById(id);
        }
         /// <summary>
        /// 添加图片
        /// </summary>
        /// <param name="objPictureFile"></param>
        /// <returns>返回图片的ID号</returns>
        public int AddPictureFile(PictureFile objPictureFile)
        {
            //如果该工程文件已存在，则替换之前的图片，并返回该图片的ID
            if (objPictureFileService.IsExistsPicture(objPictureFile.ID.ToString()) > 0)
            {
                 int result = objPictureFileService.UpdatePictureFile(objPictureFile);
                 if (result > 0)
                 {
                     return objPictureFile.PictureId;
                 }
            }
            //没存在则添加
            return objPictureFileService.AddPictureFile(objPictureFile);
        }
         /// <summary>
        /// 修改图片
        /// </summary>
        /// <param name="objPictureFile"></param>
        /// <returns></returns>
        public int UpdatePictureFile(PictureFile objPictureFile)
        {
            return objPictureFileService.UpdatePictureFile(objPictureFile);
        }
        /// <summary>
        /// 删除图片
        /// </summary>
        /// <param name="pictureId"></param>
        /// <returns></returns>
        public int DeletePictureFile(string id)
        {
            return objPictureFileService.DeletePictureFile(id);
        }
    }
}
